Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(elevator): 修复点击楼层未准确高亮对应的楼层位置信息 #3149

Open
wants to merge 2 commits into
base: v4
Choose a base branch
from

Conversation

daiwanxing
Copy link
Contributor

@daiwanxing daiwanxing commented Jul 18, 2024

这个 PR 做了什么? (简要描述所做更改)

修复了点击楼层导航,高亮的索引位置计算有误

这个 PR 是什么类型? (至少选择一个)

  • feat: 新特性提交
  • fix: bug 修复
  • docs: 文档改进
  • style: 组件样式/交互改进
  • type: 类型定义更新
  • perf: 性能、包体积优化
  • refactor: 代码重构、代码风格优化
  • test: 测试用例
  • chore(deps): 依赖升级
  • chore(demo): 演示代码改进
  • chore(locale): 国际化改进
  • chore: 其他改动(是关于什么的改动?)

这个 PR 涉及以下平台:

  • NutUI H5 @nutui/nutui
  • NutUI Taro @nutui/nutui-taro

这个 PR 是否已自测:

Summary by CodeRabbit

  • 错误修复

    • 修正了 <view> 标签的语法错误。
  • 代码重构

    • 简化了 clientHeight 计算属性和 setListGroup 函数逻辑。
    • 在高度计算中将 Math.floor 改为 Math.round
    • listViewScroll 函数中使用 const 和解构赋值来声明变量,提高了代码的可读性。
    • 优化了渲染逻辑,使模板代码更加简洁。

Copy link

coderabbitai bot commented Jul 18, 2024

Walkthrough

此次更新主要集中在简化和优化src/packages/__VUE/elevator/index.taro.vuesrc/packages/__VUE/elevator/index.vue文件中的代码,消除了多余的导入,改进了计算属性的返回逻辑,优化了函数的实现,并提升了代码的可读性和性能。

Changes

文件路径 更改摘要
.../__VUE/elevator/index.taro.vue, .../__VUE/elevator/index.vue 修复语法错误,删除nextTick导入,简化计算属性和函数逻辑,使用const和解构赋值,调整高度计算方式

🐇🎨

代码如歌简胜繁,
错误修复心欢颜。
变量解构显清晰,
逻辑简化更自然。


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jul 18, 2024

Codecov Report

Attention: Patch coverage is 53.84615% with 6 lines in your changes missing coverage. Please review.

Project coverage is 81.19%. Comparing base (a415d0b) to head (9645921).
Report is 11 commits behind head on v4.

Files with missing lines Patch % Lines
src/packages/__VUE/elevator/index.vue 53.84% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               v4    #3149      +/-   ##
==========================================
- Coverage   81.20%   81.19%   -0.01%     
==========================================
  Files         226      226              
  Lines       18139    18137       -2     
  Branches     2485     2484       -1     
==========================================
- Hits        14729    14726       -3     
- Misses       3392     3393       +1     
  Partials       18       18              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a415d0b and 287ab78.

Files selected for processing (1)
  • src/packages/__VUE/elevator/index.taro.vue (6 hunks)
Additional comments not posted (6)
src/packages/__VUE/elevator/index.taro.vue (6)

57-57: 移除 nextTick 导入

nextTick 已被移除,代码简化了。


119-119: 计算属性 clientHeight

计算属性 clientHeight 实现正确。


135-137: 简化函数 setListGroup

函数 setListGroup 逻辑简化,确保只有非空元素被添加到 state.listGroup 中。


147-147: 使用 Math.round 进行高度计算

使用 Math.round 代替 Math.floor 可以提供更准确的高度计算。


165-166: 函数 touchStart

函数 touchStart 实现正确,设置初始触摸状态并滚动到相应的索引。


196-204: 重构函数 listViewScroll

使用 const 和解构赋值提高了代码的可读性和可维护性。

@daiwanxing
Copy link
Contributor Author

related issue #3145

假设某个楼层的区间在 [200, 300],为 scroll-view 组件指定 scrollTop 值并不会恰好的落在设定的值(如果设定 scrollTop: 200 可能滚动到的距离是 199.6901323132112),可能偏差 0.5 以内像素。旧逻辑如果用 Math.floor 无法精确的落在指定区间的索引,改成了 Math.round 解决。

@eiinu eiinu linked an issue Jul 18, 2024 that may be closed by this pull request
@eiinu
Copy link
Member

eiinu commented Jul 18, 2024

需要将逻辑修改同步到 index.vue 文件后 pnpm dev 测试 H5 场景

@daiwanxing
Copy link
Contributor Author

daiwanxing commented Jul 19, 2024

需要将逻辑修改同步到 index.vue 文件后 pnpm dev 测试 H5 场景

我在 index.taro.vue 改动了后, h5 环境是能测试通过的,一直没明白 index.vueindex.taro.vue 的区别,这俩文件的模板结构有点不一样🧐

@eiinu
Copy link
Member

eiinu commented Jul 19, 2024

需要将逻辑修改同步到 index.vue 文件后 pnpm dev 测试 H5 场景

我在 index.taro.vue 改动了后, h5 环境是能测试通过的,一直没明白 index.vueindex.taro.vue 的区别,这俩文件的模板结构有点不一样🧐

可以参考仓库内的贡献指南(contributing)。
index.vue 是纯 H5 的组件(pnpm dev 启动),index.taro.vue 是依赖于 Taro 框架的组件(pnpm dev:h5 和 pnpm dev:weapp)。
前者对应的是 @nutui/nutui,后者对应的是@nutui/nutui-taro。

@daiwanxing
Copy link
Contributor Author

需要将逻辑修改同步到 index.vue 文件后 pnpm dev 测试 H5 场景

我在 index.taro.vue 改动了后, h5 环境是能测试通过的,一直没明白 index.vueindex.taro.vue 的区别,这俩文件的模板结构有点不一样🧐

可以参考仓库内的贡献指南(contributing)。 index.vue 是纯 H5 的组件(pnpm dev 启动),index.taro.vue 是依赖于 Taro 框架的组件(pnpm dev:h5 和 pnpm dev:weapp)。 前者对应的是 @nutui/nutui,后者对应的是@nutui/nutui-taro。

got it. 我调整下

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 287ab78 and 9645921.

Files selected for processing (1)
  • src/packages/__VUE/elevator/index.vue (4 hunks)
Additional comments not posted (5)
src/packages/__VUE/elevator/index.vue (5)

24-24: 简化插值表达式

将插值表达式简化为单行,提高了代码的可读性,并且不影响功能。


96-96: 简化计算属性

将计算属性简化为箭头函数,减少了冗余,同时保持了相同的逻辑。


104-106: 优化 setListGroup 函数

移除了 nextTick 包装器,增强了性能,避免了不必要的异步调度。


114-114: 改进 calculateHeight 函数

Math.floor 改为 Math.round,以提供更准确的元素渲染高度。


162-170: 优化 listViewScroll 函数

通过合并变量声明和使用解构赋值替换高度比较,改进了代码的清晰度并减少了认知负担。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

elevator控件索引点击后,高亮位置错误
2 participants